<?php include('header.php'); ?>
<?php

use \LaneWeChat\Core\Db;
use \LaneWeChat\Core\Ext;
include '/var/www/html/wx/wechat/core/ext.lib.php';
include '/var/www/html/wx/wechat/core/db.lib.php';
$accounts = \LaneWeChat\Core\Ext::AccountList($_SESSION['sid']);

include_once '/var/www/html/new/d/module/common/Db.class.php';
$dbConf = include '/var/www/html/new/d/module/common/db.conf.php';// 远端服务器配置信息
\PFT\Db::Conf($dbConf['remote_1']);
$sql = <<<SQL
SELECT `id`,`fid`, `nick_name`, `user_name`, `appid`, `service_type_info`,
 `verify_type_info`, `head_img`, `qrcode_url`, `isconnect`,
 `func_info`, `authorizer_refresh_token` FROM pft_wx_open
 WHERE fid={$_SESSION ['sid']} AND isconnect=0
SQL;
//echo $sql;
$stmt = \PFT\Db::Connect()->prepare($sql);
$stmt->execute();
$open_account = $stmt->fetchAll(PDO::FETCH_ASSOC);
//print_r($open_account);
$service_type_info = array(
    0=>'订阅号', 1=>'升级后的订阅号',2=>'服务号',
);
//授权方认证类型
$verify_type_info = array(
    -1 => '未认证',
    0 => '微信认证',
    1 => '新浪微博认证',
    2 => '腾讯微博认证',
    3 => '已资质认证通过但还未通过名称认证',
    4 => '已资质认证通过,',
    5 => '已资质认证通过',
);
?>

<title>微信公众号配置</title>
<style>
 #accountDetailUl li{list-style: none;height: 60px;}
    .wx-img{width: 120px;}
    #open-account li{list-style: none;margin-bottom:10px;}
	.setleft{margin-left:105px;margin-top:-20px;}
	.setleft img{border:1px solid #E5E5E5;}
	.setwidth label{width:100px;text-align:right;}
</style>
</head>
<body>
	<div class="navbar navbar-inverse navbar-static-top" role="navigation" style="position:static;">
		<div class="container-fluid">
			<ul class="nav navbar-nav">
				<li><a href="http://www.12301.cc"><i class="fa fa-reply-all"></i>返回系统</a></li>
			</ul>
		</div>
	</div>
	<div class="container-fluid">
		<div class="row">
            <?php include('leftbar.php') ?>
            <div class="col-xs-12 col-sm-9 col-lg-10">
                <?php if(count($open_account)):?>
                    <?php foreach($open_account as $list):?>
                        <div class="col-xs-12 col-sm-9 col-lg-6">
                            <div class="panel panel-default">
                                <div class="panel-heading"><?=$list['nick_name'];?></div>
                                <div id="account-panel-body" class="panel-body">
                                    <form class="form-horizontal" role="form">
                                       <ul id="open-account" class="accountDetailUl setwidth">
                                            <li class="item clearfix ">
                                                <label class="lt">公众号名称：</label>
												<span id="account_type"><?=$list['nick_name'];?></span>
                                                
                                            </li>
											<li class="item clearfix">
                                                <label class="lt">公众号类型：</label>
												<span><?=$service_type_info[$list['service_type_info']]?></span>
                                          
                                            </li>
                                            <li class="item clearfix">
                                                <label class="lt">认证类型：</label>
												<span><?=$verify_type_info[$list['verify_type_info']]?></span>
                                                
                                            </li>
                                            <li class="item clearfix" style="height: 140px;">
                                                <label class="lt">二维码：</label>
                                                <div class="rt setleft"><img src="<?=$list['qrcode_url']?>" class="wx-img" ></div>
                                            </li>
											<li class="item clearfix" style="height: 140px;">
                                                <label class="lt">头像：</label>
                                                <div class="rt setleft"><img src="<?=$list['head_img']?>" class="wx-img"></div>
                                            </li>
                                        </ul>
                                    </form>
                                </div>
                            </div>
                        </div>
                    <?php endforeach;?>
                <?php else:?>
                    <div class="panel panel-default">
                        <div id="account-panel-body" class="panel-body">
                            您还没有添加过微信号，<a class="btn btn-primary" href="open_auth.php"><i class="fa fa-plus"></i> 添加公众号</a>
                        </div>
                    </div>
                <?php endif;?>
                <?php if(count($accounts)):?>
                    <?php foreach($accounts as $account):?>
                        <div class="col-xs-12 col-sm-9 col-lg-6">
                            <div class="panel panel-default">
                            <div class="panel-heading"><?=$account['name'];?></div>
                            <div id="account-panel-body" class="panel-body">
                                <form class="form-horizontal" role="form">
                                    <ul id="accountDetailUl" class="accountDetailUl">
                                        <li class="item clearfix">
                                            <label class="lt">接入状态</label>
                                            <div class="rt">
                                                <span id="account_status">
                                                    <?=$account['isconnect']==0 ? '<span class="label label-success">已接入</span>'
                                                        :'<span class="label label-warning">未接入</span>查看<a href="add_account_finish.html?account_id='.$account['id'].'">接入指南</a>';?>
                                                </span>
                                            </div>
                                        </li>
                                        <li class="item clearfix">
                                            <label class="lt">公众号类型</label>
                                            <div class="rt"><span id="account_type"><?=$account['ac_type'];?></span></div>
                                        </li>
                                        <li class="item clearfix">
                                            <label class="lt">URL</label>
                                            <div class="rt"><span id="account_url"><?=$account['url'];?></span></div>
                                        </li>
                                        <li class="item clearfix">
                                            <label class="lt">Token</label>
                                            <div class="rt"><span id="account_token"><?=$account['token'];?></span></div>
                                        </li>
                                        <li class="item clearfix">
                                            <label class="lt aeskey">EncodingAESKey<span style="display:block">(消息加解密密钥)</span></label>
                                            <div class="rt"><span id="account_EncodingAESKey"><?=$account['encodingAESKey'];?></span></div>
                                        </li>
                                    </ul>
                                </form>
                            </div>
                            <div class="panel-footer clearfix">
                                <div class="btn-group pull-right">
                                    <a class="btn btn-default" href="add_account.html?account_id=<?=$account['id']?>"><i class="fa fa-edit"></i> 编辑</a>
                                    <a class="btn btn-default" href="add_account.html?account_id=<?=$account['id']?>"><i class="fa fa-cog fa-spin"></i> 管理</a>
                                    <a class="btn btn-default" href="javascript:;" id='del' data-id="<?=$account['id']?>" onclick="del()"><i class="fa fa-times"></i> 删除</a>
                                </div>
                            </div>
                        </div>
                        </div>
                    <?php endforeach;?>
                <?php else:?>

                <?php endif;?>
            </div>
		</div>
	</div>
	<div style="display:none" id="gMaskLayer" class="gMaskLayer"></div>
    <script src="http://www.12301.cc/wx_public/zclip/jquery.zclip.min.js"></script>
    <script>
        $(function(){
            $(".clipLinkBtn").zclip({
                path: "/wx_public/zclip/ZeroClipboard.swf",
                copy: function(){
                    return $(this).attr("data-link");
                },
                deforeCopy : function(){},
                afterCopy : function(){
                    var btn = $(this);
                    btn.text("已复制到剪贴板").addClass("success");
                    WXB.G.Delay.set(function(){
                        btn.removeClass("success").text("复制");
                    },2 * 1000)
                }
            });           
        });
        function del(){
            if (!confirm('确认要删除吗？'))
                return false;
            var account_id = $('#del').data('id');
                $.post('ichat.php', {action:'RemoveAccount', account:account_id}, function(res){
                    if (res==1) {
                        alert('删除成功');
                        location.reload();
                    } else {
                        console.log(res);
                    }
                });
            };
    </script>

</body>